<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
    <%@include file="../includes/common.jsp" %>
    <%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
    <%@ page contentType="text/html;charset=UTF-8" %>

    <title>课件上传列表</title>
</head>
<body>
<div class="container-fluid" style="padding: 0">

        <div style="padding: 10px">
            <div class="control-group">
                <form class="form-horizontal">
                    <div class="control-group">
                        <label class="control-label">账号</label>
                        <div class="controls">
                            <input type="text" id="loginName" name="loginName"value="${user.loginName}">
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">密码</label>
                        <div class="controls">
                            <input type="password" id="password" name="password" value="${user.password}">
                            <a class="btn btn-primary" id="changePassword" onclick="changePassword(${user.id})">修改密码</a>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">性别</label>
                        <div class="controls">
                            男<input type="radio"  name="sex" value="0" <c:if test="${user.sex==0}">checked="checked" </c:if> />
                            女<input type="radio"  name="sex" value="1" <c:if test="${user.sex==1}">checked="checked" </c:if>>
                            保密<input type="radio"  name="sex" value="2" <c:if test="${user.sex==2}">checked="checked" </c:if>>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">生日</label>
                        <div class="controls">
                            <input type="text"  data-date-format="yyyy-mm-dd" id="birthday" name="birthday" value="${user.birthday}" onclick="getBirthday()" readonly="readonly">
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">邮箱</label>
                        <div class="controls">
                            <input type="text" value="${user.email}" id="email" name="email">
                        </div>
                    </div>

                    <div class="control-group">
                        <label class="control-label">城市</label>
                        <div class="controls">
                            <input type="text" id="city" name="city" value="${user.city}">
                            <a class="btn btn-primary" id="changeCity"  onclick="changeCitys()">换个城市</a>
                        </div><br/>
                        <div class="controls" id="city_1"  style="display: none">
                            <select class="prov" id="prov" onchange="getProv()"></select>
                            <select class="city" disabled="disabled" id="citys" onchange="getCity()"></select>
                        </div>
                    </div>
                    <br/><br/>
                    <div class="controls">
                        <input type="button" id="saves" class="btn btn-primary" onclick="save()" value="保存"/>
                        <input type="button" onclick="quit()" class="btn btn-primary" value="取消"/>
                    </div>
                </form>


                <div id="dataEdit" closed="true" modal="true" style="overflow: hidden">
                    <iframe style="width: 100%;height: 100%"
                            id="contentFrame"
                            name="contentFrame"
                            marginheight="0"
                            marginwidth="0"
                            frameborder="0" src=""
                            allowTransparency="true">
                    </iframe>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>
<script type="text/javascript" src="<c:url value="/js/jquery.cityselect.js" />"></script>
<script type="text/javascript">
    var today = new Date().dateFormat();
    var dateConf = {
        language: 'zh-CN',
        endDate: today,
        weekStart: 1,
        todayBtn: true,
        autoClose: true,
        todayHighlight: 1,
        startView: 2,
        minView: 2,
        forceParse: 0
    };
    var rules = {
        objInfo: {
            loginName: {
                checkEmpty: ["loginName", "用户名 "],
                ajax: [basePath + "admin/user/checkRepeatLoginName", {}, {loginName: "$('#loginName').val().trim()",oldName:"'${user.loginName}'"},
                    backFunc, "text", "POST"]
            },
            birthday: {
                checkEmpty: ["birthday", "生日"]
            },
            email: {
                checkEmpty: ["email", "邮箱"]
            },
            city: {
                checkEmpty: ["city", "城市"]
            }

        }
    };
    function backFunc(data, returnObj) {
        returnObj.obj = $('#loginName');
        returnObj.errMsg = "用户名已存在！";
        if (data == "true") {
            returnObj.bool = true;
        }
        if (data == "false") {
            returnObj.bool = false;
        }
        return returnObj;
    }
    function getBirthday(){
        $("#birthday").datetimepicker(dateConf);
        autoComplete();
        JC.inputInit();
    }
    $(function(){
        $("#city_1").citySelect({
            nodata:"none",
            required:false
        });
    });
    function getCity(){
        $("#city").attr("value", $("#prov").val()+","+ $("#citys").val());
    }
    function getProv(){
        $("#citys").attr("value","");
        $("#city").attr("value", $("#prov").val());
    }
    function addUser() {
        $("#contentFrame")[0].contentWindow.document.write("");
        $("#contentFrame").attr("src", basePath + "scorm/addUserDo");
        $('#dataEdit').dialog({
            title: '<spring:message code="add"/>',
            height: 400,
            width: 600
        })
        $('#dataEdit').dialog('open');
    }

    function save() {
        if(!JC.validate(rules)) return;
            $.ajax({
                url: basePath + "admin/user/editUser",
                data: {
                    id:${user.id},
                    loginName: $("#loginName").val().trim(),
                    sex: $("input[name=sex]:checked").val(),
                    birthday:$("#birthday").val().trim(),
                    email:$("#email").val().trim(),
                    city:$("#city").val().trim()
                },
                dataType: "json",
                type: "POST",
                success: function () {
                    $.messager.alert("提示", "保存成功！", "",function () {
                      window.location.reload();
                    });
                },
                error: doError
            })
    }
    function changeCitys(){
        $("#city_1").show();
    }

    function changePassword(id) {
        $("#contentFrame")[0].contentWindow.document.write("");
        $("#contentFrame").attr("src", basePath + "admin/user/changePasswordDo?id="+id);
        $('#dataEdit').dialog({
            title: '修改密码',
            height: 400,
            width: 600
        })
        $('#dataEdit').dialog('open');
    }

    function listFriend(){
        location.href=basePath+"consumer/listAllFriendDo";
    }


</script>